package concurrent.threadSafe;

import java.util.concurrent.CountDownLatch;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName ThreadSafeDemo.java
 * @Description 三个线程同时执行
 * @createTime 2021年04月14日 00:08:00
 */


public class ThreadSafeDemo {
    public int count = 0;

    public static void main(String[] args) throws InterruptedException {
        int size = 3;

        ThreadSafeDemo threadSafeDemo = new ThreadSafeDemo();

        CountDownLatch countDownLatch = new CountDownLatch(1);

        for (int i = 0; i <size ; i++) {
            new Thread(()->{
                try {
                    //等待
                    countDownLatch.await();
                    System.out.println(System.currentTimeMillis());
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        //休眠5s为了for循环里的线程准备好。
        Thread.sleep(5000);
        countDownLatch.countDown();

    }
}
